using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace InfiniTec.Exchange.Notifications
{
	/// <summary>
	/// This exception is thrown when a call to an Exchange CAS role fails.
	/// </summary>
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors"), Serializable]
	public sealed class WebServiceInvocationFailedException : Exception
	{
		private readonly string _ErrorDescription;
		private readonly string _ErrorCode;


		/// <summary>
		/// Gets the error code.
		/// </summary>
		/// <value>The error code.</value>
		public string ErrorCode { get { return _ErrorCode; } }

		/// <summary>
		/// Gets the error description.
		/// </summary>
		/// <value>The error description.</value>
		public string ErrorDescription
		{
			get { return _ErrorDescription; }
		}

		/// <summary>
		/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic). </exception>
		/// <PermissionSet>
		/// 	<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
		/// 	<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
		/// </PermissionSet>
		[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);

			info.AddValue("ErrorDescription", _ErrorDescription);
			info.AddValue("ErrorCode", _ErrorCode);
		}


		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceInvocationFailedException"/> class.
		/// </summary>
		public WebServiceInvocationFailedException() { }

		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceInvocationFailedException"/> class.
		/// </summary>
		/// <param name="errorCode"></param>
		/// <param name="message">The message.</param>
		/// <param name="errorDescription">A detailed descriptions of the error</param>
		public WebServiceInvocationFailedException(string errorDescription, string errorCode, string message)
			: base(message)
		{
			_ErrorDescription = errorDescription;
			_ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceInvocationFailedException"/> class.
		/// </summary>
		/// <param name="errorDescription">A detailed descriptions of the error</param>
		/// <param name="errorCode">The error code.</param>
		/// <param name="message">The message.</param>
		/// <param name="innerException">The inner exception.</param>
		public WebServiceInvocationFailedException(string errorDescription, string errorCode, string message, Exception innerException)
			: base(message, innerException)
		{
			_ErrorDescription = errorDescription;
			_ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceInvocationFailedException"/> class.
		/// </summary>
		/// <param name="context">The <see cref="StreamingContext"/> to recreate the exception from.</param>
		/// <param name="info">The <see cref="SerializationInfo"/> to recreate the exception from.</param>
		private WebServiceInvocationFailedException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			_ErrorDescription = info.GetString("ErrorDescription");
			_ErrorCode = info.GetString("ErrorCode");
		}
	}
}